package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-09-03
 * Time: 21:38
 */
class MyRunnable implements Runnable{
    @Override
    public void run() {
        while (true) {
            System.out.println("hello thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class demo2 {
    //创建线程不仅可以用继承Thread，还有一种方法是实现Runnable接口，重写run
    public static void main(String[] args) {
        MyRunnable   runnable=new MyRunnable();
        Thread  t=new Thread(runnable);
        t.start();
        while(true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
